// index.js
// 获取应用实例
// const app = getApp()
const _app = require('../../npm/app');
class Index extends _app.Component{
  constructor() {
    super();
    this.state = {
      count: 0,
    };
  }
  componentDidMount() {
    console.log('执行componentDidMount');
    this.setState({
      count: 1,
    });
  }
  onAddClick() {
    this.setState({
      count: this.state.count + 1,
    });
  }
  onReduceClick() {
    this.setState({
      count: this.state.count - 1,
    });
  }
  createData() { // react render内部可能会增加变量 所以通过createData方法来处理render内部新增的变量
    this._state = arguments[0];
    const text = this.state.count % 2 === 0 ? '偶数' : '奇数';
    return {
      ...this._state,
      text,
    };
  }
}
Index.$$events = ['onAddClick', 'onReduceClick']
Page(_app.createPage(Index));
